package tugas.akhir.jason;


import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

public class dr8_cameramiddas extends Activity implements View.OnClickListener{
	
	ImageButton ib;
	Button b;
	ImageView iv;
	Intent i;
	int cameraResult;
	final static int cameraData = 0;
	Bitmap bmp;
	protected MyDBHelper myDBHelper;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dr8_cameramiddas);
        initialize();
        InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
        bmp = BitmapFactory.decodeStream(is);
	 
    }

	private void initialize() {
		// TODO Auto-generated method stub
		iv = (ImageView) findViewById (R.id.ivReturnedPic);
		ib = (ImageButton) findViewById (R.id.ibTakePic);
		b = (Button) findViewById (R.id.bSetWall);
		b.setOnClickListener(this);
		ib.setOnClickListener(this);
		myDBHelper=new MyDBHelper(this);	
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()){
		case R.id.bSetWall:
		  { startActivity(new Intent(dr8_cameramiddas.this, dr8_mulmed.class)); }
 	    
			break;
		case R.id.ibTakePic:
			i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
			startActivityForResult(i, cameraData);
			     
			break;
			}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK);
			Bundle extras = data.getExtras();
			bmp = (Bitmap) extras.get("data");
			iv.setImageBitmap(bmp);
			
			ByteArrayOutputStream blob = new ByteArrayOutputStream();
	        bmp.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, blob);
	        byte[] bitmapdata = blob.toByteArray();
	        variabelstatis.image = bitmapdata;
	 	  
	 	    startActivity(new Intent(dr8_cameramiddas.this,dr8_mulmed.class));	 	  
	}
}